<!DOCTYPE HTML PUBLIC "-//ORA//DTD CD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>[Chapter 19] The java.awt.datatransfer Package</TITLE>
<META NAME="author" CONTENT="David Flanagan">
<META NAME="date" CONTENT="Thu Jul 31 16:12:08 1997">
<META NAME="form" CONTENT="html">
<META NAME="metadata" CONTENT="dublincore.0.1">
<META NAME="objecttype" CONTENT="book part">
<META NAME="otheragent" CONTENT="gmat dbtohtml">
<META NAME="publisher" CONTENT="O'Reilly &amp; Associates, Inc.">
<META NAME="source" CONTENT="SGML">
<META NAME="subject" CONTENT="Java">
<META NAME="title" CONTENT="Java in a Nutshell">
<META HTTP-EQUIV="Content-Script-Type" CONTENT="text/javascript">
</HEAD>
<body vlink="#551a8b" alink="#ff0000" text="#000000" bgcolor="#FFFFFF" link="#0000ee">

<DIV CLASS=htmlnav>
<H1><a href='index.htm'><IMG SRC="gifs/smbanner.gif"
     ALT="Java in a Nutshell" border=0></a></H1>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch18_61.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><B><FONT FACE="ARIEL,HELVETICA,HELV,SANSERIF" SIZE="-1">Chapter 19</FONT></B></TD>
<td width=172 align=right valign=top><A HREF="ch19_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
</table>

&nbsp;
<hr align=left width=515>
</DIV>
<H1 CLASS=chapter><A CLASS="TITLE" NAME="JNUT2-CH-19">19. The java.awt.datatransfer Package</A></H1>

<DIV CLASS=htmltoc>

<p>
<b>Contents:</b><br>
java.awt.datatransfer.Clipboard (JDK 1.1)<br>
<A HREF="ch19_02.htm">java.awt.datatransfer.ClipboardOwner (JDK 1.1)</A><BR>
<A HREF="ch19_03.htm">java.awt.datatransfer.DataFlavor (JDK 1.1)</A><BR>
<A HREF="ch19_04.htm">java.awt.datatransfer.StringSelection (JDK 1.1)</A><BR>
<A HREF="ch19_05.htm">java.awt.datatransfer.Transferable (JDK 1.1)</A><BR>
<A HREF="ch19_06.htm">java.awt.datatransfer.UnsupportedFlavorException (JDK 1.1)</A><BR>

<p>
</DIV>

<P CLASS=para>
<A NAME="CH19.JAVA.AWT.DAT1"></A>This small package contains classes and interfaces that
support a generic inter-application data transfer mechanism.
It also provides support for cut-and-paste data transfer on top of that
mechanism.  This package, and all of its classes and
interfaces, are new in Java 1.1.  Future releases of Java
are likely to extend this package with support for data
transfer through drag-and-drop.

<P CLASS=para>
<A HREF="ch19_01.htm#JNUT2-CH-19-FIG-1">Figure 19.1</A>
shows the class hierarchy for <tt CLASS=literal>java.datatransfer</tt>.
<tt CLASS=literal>DataFlavor</tt> and <tt CLASS=literal>Transferable</tt> define the basic
data transfer mechanism.  <tt CLASS=literal>Clipboard</tt> and
<tt CLASS=literal>ClipboardOwner</tt> provide support for cut-and-paste.
<tt CLASS=literal>StringSelection</tt> is a convenience class that makes it
particularly easy to transfer textual data between
applications.

<DIV CLASS=figure>
<h4 CLASS=figure><A CLASS="TITLE" NAME="JNUT2-CH-19-FIG-1">Figure 19.1: The java.awt.datatransfer package</A></h4>


<p>
<img align=middle src="./figs/jn2_1901.gif" alt="[Graphic: Figure 19-1]" width=464 height=209 border=0>

</DIV>

<DIV CLASS=sect1>
<h2 CLASS=sect1><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-1">19.1 java.awt.datatransfer.Clipboard (JDK 1.1)</A></h2>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-1.1"></A></h3>
</DIV>

<P CLASS=para>
This class represents a clipboard on which data may be
transferred using the cut-and-paste metaphor.  When data is
"cut," it should be encapsulated in a <tt CLASS=literal>Transferable</tt>
object and registered with a <tt CLASS=literal>Clipboard</tt> object by
calling <tt CLASS=literal>setContents()</tt>.  A <tt CLASS=literal>Clipboard</tt> can only
hold a single piece of data at a time, so a
<tt CLASS=literal>ClipboardOwner</tt> object must be specified when data is
placed on the clipboard.  This object is notified that
it no longer "owns" the clipboard when the data is
replaced by other, more recent, data.

<P CLASS=para>
When a "paste" is requested by the user, an application
requests the data on the <tt CLASS=literal>Clipboard</tt> by calling
<tt CLASS=literal>getContents()</tt>, which returns a <tt CLASS=literal>Transferable</tt>
object.  The methods of this object can be used to negotiate
a mutually-compatible data format and to actually transfer
the data.

<P CLASS=para>
A clipboard name is passed to the <tt CLASS=literal>Clipboard()</tt>
constructor, and may be retrieved with <tt CLASS=literal>getName()</tt>.
This name is not actually used in Java 1.1, however.

<P CLASS=para>
Note that while applications can create their own private
<tt CLASS=literal>Clipboard</tt> objects for intra-application
cut-and-paste, it is more common for them to use the system
clipboard to enable cut-and-paste between applications.  You
can obtain the system clipboard by calling the
<tt CLASS=literal>getSystemClipboard()</tt> method of the current
<tt CLASS=literal>Toolkit</tt> object.  Untrusted applet code is not
allowed to access the system clipboard, so untrusted applets cannot
participate in inter-application cut-and-paste.

<DIV CLASS=screen>
<P>
<PRE>
public class <tt CLASS=literal>Clipboard</tt> extends Object {
    // <tt CLASS=literal>Public Constructor</tt>
            public <tt CLASS=literal>Clipboard</tt>(String <tt CLASS=literal>name</tt>);
    // <tt CLASS=literal>Protected Instance Variables</tt>
            protected Transferable <tt CLASS=literal>contents</tt>;
            protected ClipboardOwner <tt CLASS=literal>owner</tt>;
    // <tt CLASS=literal>Public Instance Methods</tt>
            public synchronized Transferable <tt CLASS=literal>getContents</tt>(Object <tt CLASS=literal>requestor</tt>);
            public String <tt CLASS=literal>getName</tt>();
            public synchronized void <tt CLASS=literal>setContents</tt>(Transferable <tt CLASS=literal>contents</tt>, ClipboardOwner <tt CLASS=literal>owner</tt>);
}
</PRE>
</DIV>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-1.2">Passed To:</A></h3>

<P CLASS=para>
<tt CLASS=literal>ClipboardOwner.lostOwnership(), 
StringSelection.lostOwnership()</tt>

</DIV>

<DIV CLASS=sect2>
<h3 CLASS=sect2><A CLASS="TITLE" NAME="JNUT2-CH-19-SECT-1.3">Returned By:</A></h3>

<P CLASS=para>
<tt CLASS=literal>Toolkit.getSystemClipboard()</tt>

</DIV>

</DIV>


<DIV CLASS=htmlnav>

<P>
<HR align=left width=515>
<table width=515 border=0 cellpadding=0 cellspacing=0>
<tr>
<td width=172 align=left valign=top><A HREF="ch18_61.htm"><IMG SRC="gifs/txtpreva.gif" ALT="Previous" border=0></A></td>
<td width=171 align=center valign=top><a href="index.htm"><img src='gifs/txthome.gif' border=0 alt='Home'></a></td>
<td width=172 align=right valign=top><A HREF="ch19_02.htm"><IMG SRC="gifs/txtnexta.gif" ALT="Next" border=0></A></td>
</tr>
<tr>
<td width=172 align=left valign=top>java.awt.Window (JDK 1.0)</td>
<td width=171 align=center valign=top><a href="index/idx_0.htm"><img src='gifs/index.gif' alt='Book Index' border=0></a></td>
<td width=172 align=right valign=top>java.awt.datatransfer.ClipboardOwner (JDK 1.1)</td>
</tr>
</table>
<hr align=left width=515>

<IMG SRC="gifs/smnavbar.gif" USEMAP="#map" BORDER=0> 
<MAP NAME="map"> 
<AREA SHAPE=RECT COORDS="0,0,108,15" HREF="../javanut/index.htm"
alt="Java in a Nutshell"> 
<AREA SHAPE=RECT COORDS="109,0,200,15" HREF="../langref/index.htm" 
alt="Java Language Reference"> 
<AREA SHAPE=RECT COORDS="203,0,290,15" HREF="../awt/index.htm" 
alt="Java AWT"> 
<AREA SHAPE=RECT COORDS="291,0,419,15" HREF="../fclass/index.htm" 
alt="Java Fundamental Classes"> 
<AREA SHAPE=RECT COORDS="421,0,514,15" HREF="../exp/index.htm" 
alt="Exploring Java"> 
</MAP>
</DIV>

</BODY>
</HTML>
